{% extends 'admin/admin_base.html' %}
{%import '_macros.html' as macros%}
    {% block title %}组{% endblock %}
{% block head %}
    {{ super() }}
{% endblock %}
{% block body %}
    <div class="boong">
  <ul class="nav nav-tabs">
      <li class="active">
        <a href="{{ url_for('mygroup.index')}}">列表</a>
    </li>
    <li><a href="{{ url_for('mygroup.create', change='create') }}">增加</a></li>
    <li onclick="change()"><a href="javascript:void(0)">修改</a></li>
    <li onclick="change_de()"><a href="javascript:void(0)">删除</a></li>

    <li><div class="form-group">
        <input type="text" id="search" name="search" value="" class="col-md-2 form-control" placeholder="请输入要查找的组名"></div></li>
    <li onclick="change_ce()"><a href="javascript:void(0)">搜索</a></li>
  </ul>
<table class="table table-striped table-bordered model-list" cellspacing="10">
    <tbody><tr class="list-title">
        <th class="list-checkbox-column">
            <input type="checkbox" name="rowtoggle" class="action-rowtoggle" id="all" title="选择所有记录" onclick="cc()">
        </th>
        <td width="130px" style="text-align: center">ID</td>
        <td width="130px" style="text-align: center">名称</td>
        <td width="138px" style="text-align: center">操作</td>
    </tr>
    {% if posts == [] %}
        <tr>
            <td colspan="999"><div class="text-center">表中没有任何记录</div></td>
        </tr>
    {% else %}
        {% for i in posts %}
            <tr>
            <td><input type="checkbox" name="rowid" class="action-checkbox" id="{{ loop.index }}" value="{{ loop.index }}" title="选择记录" onclick="bc()"></td>
            <td class="list-name"><a href="#" status="1" name="{{ loop.index }}" class="tata">{{ i['id'] }}</a>
    {#            <em class="tl-icon2">可转让</em><em class="tl-icon3">A</em>#}
            </td>
{#            <td class="orange">{{ i['name'] }}</td>#}
            <td><div class="cb-left-percent"><span style="width:3%"></span></div><p class="fn-left">{{ i['name'] }}</p></td>
            <td><a href="{{ url_for('mygroup.create', change='check',number=i['id'])}}" class="list-btn btn-orange">查看</a>
                <a href="{{ url_for('mygroup.create', change='change',number=i['id'])}}" class="list-btn btn-orange">修改</a>
                <a href="javascript:void(0)" onclick="hh({{ i['id'] }})" class="list-btn btn-orange">删除</a>
            </td>
            </tr>
        {% endfor %}
        </tbody>
        </table>
        {{macros.pagination_widget(pagination,'mygroup.index')}}
{#    <ul class="breadcrumb"  onclick="gg()" id="fenye">#}
    {% endif %}
    </div>
{% endblock %}
{% block tail %}
    {{ super() }}
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
    <script type="text/javascript">
        function cc() {
            var gr = document.getElementById('all');
            var mq = document.getElementsByName('rowid');
            if (gr.checked){
                for(i=0;i<mq.length;i++){
                    mq[i].checked = true;
                }
            }else{
                for(i=0;i<mq.length;i++){
                    mq[i].checked = false;
                }
            }
        }
        function bc() {
            var mq = document.getElementsByName('rowid');
        }
{#        修改#}
        function change() {
            var gr = document.getElementById('all');
            var um = 0;
            var vp = 'NULL';
            var vm = 'NULL';
            if(gr.checked){
                alert("只能选择一项");
                return false;
            }else{
                var mq = document.getElementsByName('rowid');
                var mb = document.getElementsByClassName('tata');
                for(i=0;i<mq.length;i++){
                    if(mq[i].checked){
                        um +=1;
                        if(um==1){
                            vp = mq[i].value;
                            vm = mb[i].text;
                        }else{
                            alert("只能选择一项");
                            return false;
                        }
                    }
                }
                if(vp=='NULL'){
                    alert("请选择一项");
                    return false;
                }
                location.href="{{ url_for('mygroup.create', change='change')}}?number="+vm;
            }
        }
        function hh(i) {
            var mymessage=confirm("确认删除?");
            if(mymessage==true){
                location.href="{{ url_for('mygroup.create', change='delete')}}?number="+i;
            }else{
                return false;
            }
        }
        function change_de() {
            var ll_grac = new Array();
            var num = 0;
            var mq_val = document.getElementsByName('rowid');
            var mb = document.getElementsByClassName('tata');
            for(k in mq_val){
                if(mq_val[k].checked){
{#                    ll_grac.push(mb[k].text);#}
                    ll_grac[num]=mb[k].text;
                    num +=1;
                }
            }
            if(ll_grac=='') {
                alert('请至少选择一项');
                return false;
            }
            var mymessage=confirm("确认删除?");
            if(mymessage==true){
                location.href="{{ url_for('mygroup.create', change='delete')}}?number="+JSON.stringify(ll_grac);
            }else{
                return false;
            }
        }
        function change_ce() {
            var mu = document.getElementById('search').value;
            if(mu ==''){
                alert('请输入要搜索的组名')
                return false;
            }else{
                location.href="{{ url_for('mygroup.index')}}?search="+mu;
            }
        }
    </script>
{% endblock %}